package com.hxc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxc.mapper.MainMapper;
import com.hxc.pojo.Area;
import com.hxc.pojo.Main;
import com.hxc.pojo.Stadium;
import com.hxc.pojo.Type;
import com.hxc.service.MainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class MainServiceImpl implements MainService {

    @Autowired
    MainMapper mainMapper;

    @Transactional(readOnly = true)
    @Override
    public PageInfo<Main> listAll(Main main, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Main> mains = mainMapper.listAll(main);
        return new PageInfo<>(mains);
    }

    @Override
    public int addMain(Main main) {
        int i = mainMapper.addMain(main);
        System.out.println(main.getTimeList());
        if (main.getTimeList()!=null){
            mainMapper.addTime(main.getTimeList(),main.getBid());
        }
        return i;
    }

    @Transactional(readOnly = true)
    @Override
    public List<Stadium> getStadium() {
        return mainMapper.getStadium();
    }

    @Transactional(readOnly = true)
    @Override
    public List<Type> getType() {
        return mainMapper.getType();
    }

    @Transactional(readOnly = true)
    @Override
    public List<Area> getArea() {
        return mainMapper.getArea();
    }

    @Override
    public List<Main> countNum() {
        return mainMapper.countNum();
    }
}
